/*
* Accord Software, Inc.
*
* Tutorial 06
*
* Add numbers in a circular list
*/
#include "circular.h"
/*
* build a singly linked circular list
*/
static struct list1 c1[] = {
{1, &c1[1]}, /* 0 */
{2, &c1[2]}, /* 1 */
{3, &c1[3]}, /* 2 */
{4, &c1[4]}, /* 3 */
{5, &c1[5]}, /* 4 */
{6, &c1[6]}, /* 5 */
{7, &c1[7]}, /* 6 */
{8, &c1[0]}, /* 7 */
};
/*
* build a doubly linked circular list
*/
static struct list2 c2[] = {
{1, &c2[1], &c2[7]}, /* 0 */
{2, &c2[2], &c2[0]}, /* 1 */
{3, &c2[3], &c2[1]}, /* 2 */
{4, &c2[4], &c2[2]}, /* 3 */
{5, &c2[5], &c2[3]}, /* 4 */
{6, &c2[6], &c2[4]}, /* 5 */
{7, &c2[7], &c2[5]}, /* 6 */
{8, &c2[0], &c2[6]}, /* 7 */
};
main(argc, argv)
int argc;
char *argv[];
{
char *progname = argv[0];
struct list1 *list1 = c1;
struct list2 *list2 = c2;
int j;
int loop = 2;
/*
* call ipf to add loop twice
*/
j = addcirc1(loop, list1);
printf("%s loops = %d, sum = %d\n",
progname, loop, j);
j = addcirc2(loop, FORWARD, list2);
printf("%s loops = %d, forward sum = %d\n",
progname, loop, j);
j = addcirc2(loop, BACKWARD, list2);
printf("%s loops = %d, backward sum = %d\n",
progname, loop, j);
exit(0);
}